package org.hum.scaffold.tools;

public class HexTools {
	
	public static byte[] toBytes(String hexStream) {
		byte[] bytes = new byte[hexStream.length() / 2];
		int cursor = 0;

		for (int i = 0; i < hexStream.length(); i += 2) {
			String decimal = hexStream.substring(i, i + 2);
			bytes[cursor++] = (byte) Integer.parseInt(decimal, 16);
		}

		return bytes;
	}

	public static void main(String[] args) {
		String 	hexStream = "47455420687474703a2f2f6e6577732e6373736e2e636e2f696d616765732f6d6f62696c655f76323032302e6a7320485454502f312e310d0a486f73743a6e6577732e6373736e2e636e0d0a557365722d4167656e743a4d6f7a696c6c612f352e3020284d6163696e746f73683b20496e74656c204d6163204f5320582031302e31343b2072763a38332e3029204765636b6f2f32303130303130312046697265666f782f38332e300d0a4163636570743a2a2f2a0d0a4163636570742d4c616e67756167653a7a682d434e2c7a683b713d302e382c7a682d54573b713d302e372c7a682d484b3b713d302e352c656e2d55533b713d302e332c656e3b713d302e320d0a4163636570742d456e636f64696e673a677a69702c206465666c6174650d0a436f6e6e656374696f6e3a6b6565702d616c6976650d0a636f6e74656e742d6c656e6774683a300d0a782d666f727761726465642d666f723a2f303a303a303a303a303a303a303a313a36323731330d0a0d0a0d0a";
		System.out.println(new String(toBytes(hexStream)));
				hexStream = "47455420687474703a2f2f6e6577732e6373736e2e636e2f696d616765732f6d6f62696c655f76323032302e6a7320485454502f312e310a486f73743a6e6577732e6373736e2e636e0a557365722d4167656e743a4d6f7a696c6c612f352e3020284d6163696e746f73683b20496e74656c204d6163204f5320582031302e31343b2072763a38332e3029204765636b6f2f32303130303130312046697265666f782f38332e300a4163636570743a2a2f2a0a4163636570742d4c616e67756167653a7a682d434e2c7a683b713d302e382c7a682d54573b713d302e372c7a682d484b3b713d302e352c656e2d55533b713d302e332c656e3b713d302e320a4163636570742d456e636f64696e673a677a69702c206465666c6174650a436f6e6e656374696f6e3a6b6565702d616c6976650a636f6e74656e742d6c656e6774683a300a782d666f727761726465642d666f723a2f3132372e302e302e313a35373131300a0a0a0a";
		System.out.println(new String(toBytes(hexStream)));
		hexStream = "486f73743a6e6577732e6373736e2e636e0a557365722d4167656e743a4d6f7a696c6c612f352e3020284d6163696e746f73683b20496e74656c204d6163204f5320582031302e31343b2072763a38332e3029204765636b6f2f32303130303130312046697265666f782f38332e300a4163636570743a2a2f2a0a4163636570742d4c616e67756167653a7a682d434e2c7a683b713d302e382c7a682d54573b713d302e372c7a682d484b3b713d302e352c656e2d55533b713d302e332c656e3b713d302e320a4163636570742d456e636f64696e673a677a69702c206465666c6174650a436f6e6e656374696f6e3a6b6565702d616c6976650a636f6e74656e742d6c656e6774683a300a782d666f727761726465642d666f723a2f3132372e302e302e313a35373131300a0a0a0a";
		System.out.println(new String(toBytes(hexStream)));
	}
}
